
<template>
  <div class="mainContainer">
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item :key="index" v-for="(item,index) in liveList.slice(0, 3)" @click.native="details(item)">
        <img :src="item.fakuImg" alt="">
        <p class="van-ellipsis name">{{item.title}}</p>
      </van-swipe-item>
    </van-swipe>

    <div class="iconItems">
      <van-row>
        <van-col span="6" @click="hotNews(id1)">
          <img src="/assets/image/home_icon_1@2x.png" alt="">
          <p>
            {{name1}}
          </p>
        </van-col>
        <van-col span="6" @click="opinionMore(id2)">
          <img src="/assets/image/home_icon_2@2x.png" alt="">
          <p>
            {{name2}}
          </p>
        </van-col>
        <van-col span="6" @click="classList(id6)">
          <img src="/assets/image/home_icon_3@2x.png" alt="">
          <p>
            {{name6}}
          </p>
        </van-col>
        <van-col span="6" @click="laws(id7)">
          <img src="/assets/image/home_icon_4@2x.png" alt="">
          <p>
            {{name7}}
          </p>
        </van-col>

      </van-row>

      <van-row>
        <van-col span="6" @click="jiqiren(id5)">

          <img src="/assets/image/home_icon_5@2x.png" alt="">
          <p>
            {{name5}}
          </p>
        </van-col>
        <van-col span="6" @click="garden(id3)">
          <img src="/assets/image/home_icon_6@2x.png" alt="">
          <p>
            {{name3}}
          </p>
        </van-col>
        <van-col span="6" @click="gameHome(id4)">
          <img src="/assets/image/home_icon_7@2x.png" alt="">
          <p>
            {{name4}}
          </p>
        </van-col>
        <van-col span="6" @click="toExam()">
          <img src="/assets/image/home_icon_8@2x.png" alt="">
          <p>
            {{name8}}
          </p>
        </van-col>
      </van-row>
    </div>

    <div class="classImg">
      <img @click="classList()" src="/assets/image/home_img_gg@2x.png" alt="">
    </div>

    <div class="liveList">
      <div class="title clearfix">
        <p class="fl">推荐舆情</p>
        <p class="fr" @click="opinionMore(id2)" :id="id2">更多></p>
      </div>
      <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="onLoad">
        <van-cell v-for="item in lawList" :key="item.id" :title="item.title" @click="details(item)" />
      </van-list>
    </div>
  </div>
</template>
<script>
import path from '@/network'
import API from '@/api.js'
export default {
  name: 'App',
  data () {
    return {
      name1: '',
      name2: '',
      name3: '',
      name4: '',
      name5: '',
      name6: '',
      name7: '法律法规',
      name8: '快乐通关',
      src1: '',
      src2: '',
      src3: '',
      src4: '',
      src5: '',
      src6: '',
      id1: '',
      id2: '',
      id3: '',
      id4: '',
      id5: '',
      id6: '',
      id7:'',
      total: 0,
      pagesize: 7,
      currentPage: 1,
      couseList: [],
      imgList: [],
      liveList: [],
      lawList: [],
      list: [],
      loading: false,
      finished: false,


    }
  },
  created () {
  },
  mounted () {
    this.getIndexType(1);
    this.getIndexType(2);
    this.getIndexType(3);
    this.getIndexType(4);
    this.getIndexType(5);
    this.getIndexType(6);
    this.getLiveList(0);
    this.getLawList(3);
    this.getCourseList()
  },
  methods: {
    toExam: function () {
      this.$router.push({ name: 'examList', query: { title: this.name8 } })
    },
    hotNews: function (id) {
      this.$router.push({ name: 'hotNews', query: { firstId: id, title: this.name1 } })
    },
    classList: function (id) {
      this.$router.push({ name: 'classList', query: { id: id,  title: this.name6} })

    },
    garden: function (id) {
      this.$router.push({ name: 'garden', query: { firstId: id,  title: this.name3} })
    },
    laws: function (id) {
      this.$router.push({ name: 'laws',  query:{title: this.name7}})
      // window.location.href = 'https://jiqiren.pluslegal.cn/allro/link?type=5'
    },
    jiqiren: function () {
      window.location.href = 'https://jiqiren.pluslegal.cn/'
    },
    gameHome: function (id) {
      // window.location.href = 'https://jiqiren.pluslegal.cn/faku/games/index?type=1&device_id=faku20210909' 
      window.location.href = 'http://irobot.pluslegal.cn/faku/games/index?type=1&device_id=faku20210909'
      // this.$router.push({ name: 'gameHome', query: { firstId: id, } })
      //window.location.href = 'http://192.168.1.182:10100/faku/games/index?type=1&device_id=faku20210909'
    },
    opinionMore: function (id) {
      this.$router.push({ name: 'opinionNews', query: { firstId: id, title: this.name2 } })
    },
    classDetails: function (item) {
      this.$router.push({ name: 'classDetails', query: { id: item.id, name: item.courseName, title: this.name } })
    },
  
    details: function (item) {
      this.$router.push({ name: 'details', query: { secondId: item.id, type: 1,  title: '详情'} })
    },


    //获取type
    getIndexType (id) {
      path.getIndexType(
        id
      ).then(res => {
        if (res.success === 0) {
          if (id == 1) {
            this.name1 = res.rows.name;
            this.src1 = res.rows.img;
            this.id1 = res.rows.id;
          } else if (id == 2) {
            this.name2 = res.rows.name;
            this.src2 = res.rows.img;
            this.id2 = res.rows.id;
          } else if (id == 3) {
            this.name3 = res.rows.name;
            this.src3 = res.rows.img;
            this.id3 = res.rows.id;
          }
          else if (id == 4) {
            this.name4 = res.rows.name;
            this.src4 = res.rows.img;
            this.id4 = res.rows.id;
          }
          else if (id == 5) {
            this.name5 = res.rows.name;
            this.src5 = res.rows.img;
            this.id5 = res.rows.id;
          }
          else if (id == 6) {
            this.name6 = res.rows.name;
            this.src6 = res.rows.img;
            this.id6 = res.rows.id;
          }
        }
      })
    },



    //获取list
    getLiveList (id) {
      path.getLiveList(
        this.currentPage,
        this.pagesize,
        id
      ).then(res => {
        if (res.success === 0) {
          this.liveList = res.rows
        }
      })
    },

    //获取list
    getLawList (id) {
      path.getLawList(
        this.currentPage,
        this.pagesize,
        id
      ).then(res => {
        if (res.success === 0) {
          this.lawList = res.rows;
        }
      })
    },


    //获取list
    getCourseList () {
      path.getCourseList(
        this.currentPage,
        2
      ).then(res => {
        if (res.success === 0) {
          this.couseList = res.rows
        }

      })
    },

    onLoad () {
      setTimeout(() => {
        if (this.refreshing) {
          this.list = [];
          this.refreshing = false;
        }

        for (let i = 0; i < 10; i++) {
          this.list.push(this.list.length + 1);
        }
        this.loading = false;

        if (this.list.length >= 40) {
          this.finished = true;
        }
      }, 1000);
    },

  }
}
</script>